package com.nexus.nexusgenix;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.crypto.password.PasswordEncoder;

@Slf4j
@SpringBootApplication
@MapperScan("com.nexus.**.mapper")
@ComponentScan("com.nexus.*")
// 3. 排除所有实现了MapStructConvert的接口
public class NexusGenixApplication {

    public static void main(String[] args) throws Exception {
        // if(args == null || args.length == 0) {
        //     AuthenicException error = new AuthenicException("cuowu").setData("dataaa").ERROR().setErrorCode(123);
        //     System.out.printf(error.toString());
        //     throw error;
        // }
        ConfigurableApplicationContext bean = SpringApplication.run(NexusGenixApplication.class, args);
        String encode = bean.getBean(PasswordEncoder.class).encode("123456");
        System.out.printf("encode:%s\n", encode);
        // SysUserService userService = bean.getBean(SysUserService.class);
        // List<SysUserDTO> save = userService.saveBatch(createTestUserList());
        // System.out.println(save);

    }


    // 新版本配置方式 (3.4.0及以上)
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
